/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;
import javax.swing.*;

/**
 *
 * @author daniel.camacho.rodriguez
 */
public class HelpView extends JFrame {

    private HelpViewController HVC;

    private int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    private int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;

    private JPanel mainPanel = new JPanel();
    private JPanel buttonPanel = new JPanel();
    private JPanel containPanel = new JPanel();

    private JTabbedPane contain = new JTabbedPane();
    private JEditorPane manual = new JEditorPane();
    private JEditorPane authors = new JEditorPane();
    private JEditorPane features = new JEditorPane();
    private JScrollPane featuresScroll = new JScrollPane(features,v,h);
    private JScrollPane authorsScroll = new JScrollPane(authors,v,h);
    private JScrollPane manualScroll = new JScrollPane(manual,v,h);
    private JButton accept = new JButton("Accept");

    public HelpView(HelpViewController HVC) throws IOException{
        this.HVC = HVC;
        iniComponents();
    }


    public void setVisible() {
        this.pack();
        this.setVisible(true);

    }

    public void setInvisible() {
        this.setVisible(false);
    }

    private void actionPerformedAcceptButtom(){
        this.setInvisible();
    }

    public void runWith(String what){
        if (what.equals("M")) contain.setSelectedComponent(manualScroll);
        else if (what.equals("A")) contain.setSelectedComponent(authorsScroll);
        else contain.setSelectedComponent(featuresScroll);
        this.setVisible(true);
    }


    private void iniComponents() throws IOException{
        iniFrame();
        iniMainPanel();
        assignListeners();
    }

    private void iniFrame() {
        setMinimumSize(new Dimension(480, 600));
        this.setLocationRelativeTo(null);
        this.setPreferredSize(this.getMinimumSize());
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setTitle("Help");
        setResizable(false);
        JPanel contentPane = (JPanel) this.getContentPane();
        contentPane.add(mainPanel);
    }

    private void iniMainPanel() throws IOException{

        buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        accept.setPreferredSize(new Dimension(100, 25));
        buttonPanel.add(accept);

        containPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        contain.setPreferredSize(new Dimension(430, 530));
        containPanel.add(contain);
        manual.setContentType("text/html");
        manual.setText(HVC.getPage() );
        manual.setEditable(false);
        //manual.setPage("Manual.html");
        //authors.setPage("Authors.html");
        //features.setPage("Features.html");
        contain.addTab("Manual", manualScroll);
        contain.addTab("Authors", authorsScroll);
        contain.addTab("Features", featuresScroll);

        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(containPanel, BorderLayout.CENTER);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

    }

    private void assignListeners(){
        accept.addActionListener(new ActionListener() {
            public void actionPerformed (ActionEvent event) {
                actionPerformedAcceptButtom();
            }
        });
    }
}
